# 这是数据库连接测试文件

import mysql.connector

# 建立数据库连接
try:
    connection = mysql.connector.connect(
        host="gz-cynosdbmysql-grp-1fcte1hx.sql.tencentcdb.com",
        port='29903',
        user="root",
        password="hgd123456.",
        database="AITrain"
    )

    if connection.is_connected():
        print("成功连接到 MySQL 数据库")
        cursor = connection.cursor()

        # 执行 SQL 查询
        cursor.execute("SELECT * FROM test")
        results = cursor.fetchall()

        for row in results:
            print(row)

except mysql.connector.Error as e:
    print(f"连接 MySQL 数据库时出错: {e}")

finally:
    if connection.is_connected():
        cursor.close()
        connection.close()
        print("MySQL 数据库连接已关闭")
